#!/bin/bash

# 导航服务安装脚本

APP_NAME="NavigationService"
APP_PATH="/Applications/${APP_NAME}.app"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_APP="${CURRENT_DIR}/../MacOS/${APP_NAME}"

echo "开始安装导航服务..."

# 检查是否已安装
if [ -d "$APP_PATH" ]; then
    echo "检测到已安装的导航服务，正在卸载旧版本..."
    rm -rf "$APP_PATH"
fi

# 创建应用程序目录
echo "创建应用程序目录..."
mkdir -p "/Applications"

# 复制应用程序
echo "复制应用程序文件..."
cp -R "${CURRENT_DIR}/.." "$APP_PATH"

# 设置权限
echo "设置文件权限..."
chmod +x "$APP_PATH/Contents/MacOS/${APP_NAME}"
chmod -R 755 "$APP_PATH"

# 创建启动脚本
echo "创建启动脚本..."
cat > "$APP_PATH/Contents/MacOS/start.sh" << 'EOF'
#!/bin/bash
cd "$(dirname "$0")"
./NavigationService
EOF
chmod +x "$APP_PATH/Contents/MacOS/start.sh"

echo ""
echo "✅ 导航服务安装完成！"
echo ""
echo "使用方法："
echo "1. 在 Finder 中打开 /Applications 文件夹"
echo "2. 双击 NavigationService.app 启动服务"
echo "3. 在浏览器中访问 http://localhost:8080"
echo ""
echo "卸载方法："
echo "1. 将 NavigationService.app 拖拽到废纸篓"
echo "2. 删除 ~/Library/Application Support/NavigationService 目录（如果存在）"
